package day12.dat12;


import java.util.Comparator;

public class ComparatorFact {
    public static  final  int NAME=0;
    public static  final  int PRICE=1;
    public static Comparator<Book>getInstance(int type){
        Comparator<Book> c=null;
        switch (type){
            case NAME:
                c=new Comparator<Book>() {
                    @Override
                    public int compare(Book o1, Book o2) {
                        return o1.getBookName().compareTo(o2.getBookName());
                    }


                };
                break;
            case PRICE:
                c=new Comparator<Book>() {
                    @Override
                    public int compare(Book o1, Book o2) {
                        if (o1.getPrice()>o2.getPrice())
                            return -1;
                        else if(o1.getPrice()<o2.getPrice())
                            return  1;
                        return 0;
                    }
                };
                break;

        }
        return c;
    }
}
